<template>
  <div id="comment">
      <h2>我的租用</h2>
      <el-table
    :data="tableData"
    border
    style="width: 100%">
    <el-table-column
      fixed
      prop="rentMessageId"
      label="订单号"
      width="250">
    </el-table-column>
    <el-table-column
      prop="rentStartTime"
      label="开始时间"
      width="250">
    </el-table-column>
    <el-table-column
      prop="rentEndTime"
      label="结束时间"
      width="250">
    </el-table-column>
    <el-table-column
      prop="cost"
      label="金额"
      width="220">
    </el-table-column>
    <el-table-column
      prop="parkingSpaceAddr"
      label="车位地址"
      width="330">
    </el-table-column>
    <el-table-column
      fixed="right"
      label="操作"
      width="200">
      <template slot-scope="scope">
        <el-button @click="handleClick(scope.row)" type="text" size="small">评价</el-button>
          <el-button @click="handleClick2(scope.row)" type="text" size="small">查看评价</el-button>
      </template>
      
    </el-table-column>
  </el-table>

<el-dialog title="订单评价(每笔订单只有一次评论机会哦！)" :visible.sync="dialogFormVisible">
  <el-form>

        <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入评价内容"
            v-model="textarea">
        </el-input>
        <br><br>
        <!--图片上传模块-->
        <br>
        <div class="block">
            <span class="demonstration">请您打分</span>
            <el-rate
                v-model="value"
                :colors="colors">
            </el-rate>
        </div>

  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="dialogFormVisible = false">取 消</el-button>
    <el-button type="primary" @click="submit" :disabled="onetime">确 定</el-button>
  </div>
</el-dialog>

<el-dialog title="您的评价" :visible.sync="dialogFormVisible2">
  <el-form>
      <h3>评价内容</h3>
       <el-input
            type="textarea"
            :rows="2"
            v-model="textarea2"
           :disabled="seenei">
        </el-input>
      <h3>评分</h3>
        <el-rate
            v-model="seevalue"
            disabled
            show-score
            text-color="#ff9900"
            score-template="{value}">
        </el-rate>

  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="dialogFormVisible2 = false">关闭</el-button>
  </div>
</el-dialog>


  </div>
</template>

<script>
export default {
  name: "comment",
    data() {
      return {
        tableData: [],
        gridData:[],
        dialogFormVisible: false,
        dialogFormVisible2: false,
        textarea:'',
        textarea2:"",
        seenei:true,
        seevalue:0,
        formLabelWidth: '120px',
        earned:0,
        value: null,
        colors: ['#99A9BF', '#F7BA2A', '#FF9900'],
        onetime:false,
        rentid:0,
         }
  },
    methods:{
     handleClick(a){
        console.log(a)
        this.earned=a.lessorId
        this.rentid=a.rentMessageId
        this.dialogFormVisible=true
     },
     queryalllease(){
         //查询所有租赁订单
         this.$http.get("/getallleaseByid",{
               params: {
                   userid:localStorage.getItem("loginUser")
                 }
             })
             .then(response => {
                  console.log(response)
                  this.tableData=response.data.data
                })
             .catch(error => {
                   alert(error)
                })
     },
     submit(){
         if(this.value==0){
             this.$message("请打分哦")
             return
         }
         if(this.textarea==''){
             this.$message("请填写评价内容")
             return
         }
        this.dialogFormVisible=false;
          this.$http.post("/addevaluation",{
                       evaluationGetterId:this.earned,
                       content:this.textarea,
                       score:this.value,
                       evaluationSetterId:localStorage.getItem("loginUser"),
                       rentid:this.rentid
             })
             .then(response => {
                  console.log(response)
                  if(!response.data.success){
                      this.$message(response.data.message)
                  }
                })
             .catch(error => {
                   alert(error)
                })
     },
     handleClick2(a){
        console.log(a)
        this.$http.get("/seelease",{
               params: {
                   rentid:a.rentMessageId
                 }
             })
             .then(response => {
                 console.log(response)
                 if( response.data.success){
                    this.textarea2=response.data.data.content
                    this.seevalue=response.data.data.score
                 }else{
                    this.$message(response.data.message)
                 }
                })
             .catch(error => {
                   alert(error)
                })
       this.dialogFormVisible2=true;
     }

    },

    mounted(){
     this.queryalllease();
    }
  
}
</script>